<?php namespace Admin\Controller;

class UserController extends CommonController{
	
	
	public function changePwd(){
		if(IS_POST){
		
		$password= md5($_POST['password']);
		$newPassword = md5($_POST['newPassword']);
		$confirmPassword = md5($_POST['confirmPassword']);
        //判断是否和原来的密码一致	
		 $useModel =   new \Common\Model\User;
		 //获得当前登录用户的数据
         $data = $useModel->where("uid",$_SESSION['uid'])->first();
		 //判断输入的是否和原密码一致
		 if($password!=$data['password']){
		 	$this->error("旧密码错误");
		 }
		 //验证两次输入的密码是否一致
		 if($newPassword!=$confirmPassword){
		 	$this->error("两次密码不一致");
		 }
		 //执行修改
		 $useModel->where("uid",$_SESSION['uid'])->update(array('password'=>$newPassword));
		 //重新登录
		 session_unset();
		 session_destroy();
		 $this->success("密码修改成功，请重新登录",U('Login/index'));
//		 go("Login/index");
		
		}
		
		
		View::make();
	}
	
}